package dao.oc_evaluate;

import java.io.IOException;
import java.io.Writer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.lob.SerializableClob;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import entitybean.oc_depthlist_pla.EntityBeanOc_Depthlist_Pla;
import entitybean.oc_evaluate.EntityBeanOc_Evaluate;
import entitybean.oc_news.EntityBeanOc_News;

public class DaoImpl_Oc_Evaluate extends HibernateDaoSupport implements Dao_Oc_Evaluate{

	public void Delete_Oc_Evaluate(String id) {
		List<EntityBeanOc_Evaluate> list=this.getHibernateTemplate().find("from EntityBeanOc_Evaluate where del='OFF' and id in("+id+")");	
		for(int i=0;i<list.size();i++)
		{
			EntityBeanOc_Evaluate e=list.get(i);
			e.setDel("ON");
			this.getHibernateTemplate().update(e);
			
		}
	}

	public EntityBeanOc_Evaluate Find_EntityBeanOc_Evaluate(Integer id) {
		EntityBeanOc_Evaluate e=new EntityBeanOc_Evaluate();
		List<EntityBeanOc_Evaluate> list=this.getHibernateTemplate().find("from EntityBeanOc_Evaluate where id="+id);
		if(list.size()>0)
		{
			e=list.get(0);
		}
		return e;
	}

	public List<EntityBeanOc_Evaluate> Find_EntityBeanOc_Evaluate() {
		List<EntityBeanOc_Evaluate> list=new ArrayList<EntityBeanOc_Evaluate>();
		list=this.getHibernateTemplate().find("from EntityBeanOc_Evaluate where 1=1");
		return list;
	}

	public void Insert_Oc_Evaluate(final EntityBeanOc_Evaluate e0) {
		try {
			getHibernateTemplate().execute(new HibernateCallback() {
				@SuppressWarnings("deprecation")
				public Object doInHibernate(Session arg0)
						throws HibernateException, SQLException {

					EntityBeanOc_Evaluate e1 = e0;
					e1.setNews_clob(Hibernate.createClob(" "));
					arg0.save(e1);
					arg0.flush();
					arg0.refresh(e1, LockMode.UPGRADE);
					SerializableClob sclob = (SerializableClob) e1.getNews_clob();
					java.sql.Clob jclob = sclob.getWrappedClob();
					oracle.sql.CLOB clob = (oracle.sql.CLOB) jclob;
					try {
						Writer out = clob.getCharacterOutputStream();
						out.write(e1.getNews_clob_string());
						out.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
					return null;
				}
			});
		} catch (RuntimeException re) {
			throw re;
		}
		
	}

	public void Update_Oc_Evaluate(EntityBeanOc_Evaluate e) {
		this.getHibernateTemplate().update(e);
		
	}

	public void Delete_Oc_Evaluate(EntityBeanOc_Evaluate e) {
		this.getHibernateTemplate().delete(e);
		
	}

}
